package com.java.proxy;

/**
 * @program: java_basic_knowledge
 * @description:
 * @author: CaoYong
 * @create: 2021-04-07 13:20
 **/
public class StaticProxyDemo {

    static interface IService {
        public void sayHello();
    }

    static class RealService implements IService {
        @Override
        public void sayHello() {
            System.out.println("real hello");
        }
    }

    static class ProxyService implements IService {

        private RealService iService;

        public ProxyService(RealService iService) {
            this.iService = iService;
        }

        @Override
        public void sayHello() {
            System.out.println("before hello");
            iService.sayHello();
            System.out.println("after hello");
        }
    }

    public static void main(String[] args) {
        RealService realService = new RealService();
        ProxyService proxyService = new ProxyService(realService);
        proxyService.sayHello();
    }
}
